package cn.uexpo.lhz.biz.impl;

import cn.uexpo.lhz.biz.SendMessageBiz;
import cn.uexpo.lhz.common.oldBase.BOException;
import cn.uexpo.lhz.common.oldUtils.PageRequest;
import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.common.oldUtils.PageUtils;
import cn.uexpo.lhz.dao.SendMessageMapper;
import cn.uexpo.lhz.domain.SendMessage;
import cn.uexpo.lhz.domain.SendMessageExample;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SendMessageBizImpl implements SendMessageBiz {
	@Autowired
	private SendMessageMapper sendMessageMapper;

	@Override
	public int insert(SendMessage record) throws BOException {
		return sendMessageMapper.insert(record);
	}

	@Override
	public int insertSelective(SendMessage record) throws BOException {
		return sendMessageMapper.insertSelective(record);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) throws BOException {
		return sendMessageMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int deleteEntity(SendMessage record) throws BOException {
		return sendMessageMapper.deleteByPrimaryKey(record.getId());
	}

	@Override
	public int deleteByIds(List<Integer> ids) throws BOException {
		int no=0;
		if (null!=ids) {
			for (Integer id : ids) {
				no=sendMessageMapper.deleteByPrimaryKey(id);
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int delete(List<SendMessage> records) throws BOException {
		int no=0;
		if (null!=records&&records.size()>0){
			for (SendMessage sendMessageEntity : records) {
				no=sendMessageMapper.deleteByPrimaryKey(sendMessageEntity.getId());
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int deleteByExample(SendMessageExample example) throws BOException {
		return sendMessageMapper.deleteByExample(example);
	}

	@Override
	public int updateByPrimaryKey(SendMessage record) throws BOException {
		return sendMessageMapper.updateByPrimaryKey(record);
	}

	@Override
	public int updateByPrimaryKeySelective(SendMessage record) throws BOException {
		return sendMessageMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByExampleSelective(SendMessage record, SendMessageExample example) throws BOException {
		return sendMessageMapper.updateByExampleSelective(record, example);
	}

	@Override
	public int updateByExample(SendMessage record, SendMessageExample example) throws BOException {
		return sendMessageMapper.updateByExample(record, example);
	}

	@Override
	public SendMessage selectByPrimaryKey(Integer id) throws BOException {
		return sendMessageMapper.selectByPrimaryKey(id);
	}

	@Override
	public SendMessage selectByUniqueCode(String uniqueCode) throws BOException {
		return null;
	}

	@Override
	public List<SendMessage> selectByExample(SendMessageExample example) throws BOException {
		return sendMessageMapper.selectByExample(example);
	}

	@Override
	public long countByExample(SendMessageExample example) throws BOException {
		return sendMessageMapper.countByExample(example);
	}

	@Override
	public PageResult findPage(PageRequest pageRequest, SendMessageExample example) throws BOException {
		int pageNum = pageRequest.getPage();
		int pageSize = pageRequest.getLimit();
		PageHelper.startPage(pageNum, pageSize);
		List<SendMessage> records = (List<SendMessage>) sendMessageMapper.selectByExample(example);
		return PageUtils.getPageResult(pageRequest, new PageInfo<SendMessage>(records));
	}
}
